﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized ;
using System.Text;
using System.Collections;
using System.Security.Cryptography;

namespace Alisoft.SIP
{
    public class SignatureUtil
    {
        public static String PARAMETER_SIGN = "sip_sign";

        public static String Signature(SortedDictionary<string, string> paramD, String secret)
        {
            String result = null;

            paramD.Remove(PARAMETER_SIGN);

            StringBuilder origin = new StringBuilder(secret);

            IDictionaryEnumerator myEnumerator = paramD.GetEnumerator();

            while (myEnumerator.MoveNext())
            {
                origin.Append(myEnumerator.Key).Append(myEnumerator.Value);
            }

            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();

            Console.Out.WriteLine(origin);

            result = BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(origin.ToString()))).Replace("-", "");

            return result;

        }
    }
}
